package net.jiastudy.core.config;

import net.jiastudy.biz.job.DeptAndTeacherSyncTask;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import net.jiastudy.biz.job.TestTask;

@Configuration
public class QuartzConfig {
	@Bean
	public JobDetail testTaskDetail() {
		return JobBuilder.newJob(TestTask.class).withIdentity("testTask").storeDurably().build();
	}

	@Bean
	public Trigger testTaskTrigger() {
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 */1 * * * ?");
		return TriggerBuilder.newTrigger().forJob(testTaskDetail()).withIdentity("testTask")
				.withSchedule(scheduleBuilder).build();
	}

	@Bean
	public JobDetail deptAndTeacherSyncDetail() {
		return JobBuilder.newJob(DeptAndTeacherSyncTask.class).withIdentity("deptAndTeacherSync").storeDurably().build();
	}

	@Bean
	public Trigger deptAndTeacherSyncTrigger() {
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 * * ?");
		return TriggerBuilder.newTrigger().forJob(deptAndTeacherSyncDetail()).withIdentity("deptAndTeacherSync")
				.withSchedule(scheduleBuilder).build();
	}
}
